import { uploadType, getAreaObj } from '@/utils/util'
import {configToSearch,toSearchHandle} from '@/views/datacenter/business/utils/index'

const tableConfig = {
	stripe: true,
	border: true,
	maxHeight: '80vh',
	columns: [
		{
			label: '所属区域',
			prop: 'belongAreaName',
			type: 'AplidAreaSelect',
		},
		// { label: '统一社会信用代码', prop: 'creditCode' },
		{ label: '机构名称', prop: 'organizationName' },
		{ label: '联系人', prop: 'deputyUserName' },
		{ label: '联系方式', prop: 'contactPhone',plusXing: '5,2' },
		{ label: '医疗机构名称', prop: 'medicalOrganizationName' },
		{
			label: '备案时间',
			prop: 'createTime',
			type: 'date',
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
		},
		{ label: '申请金额', prop: 'applyAmount' },
		{
			label: '申请时间',
			prop: 'applyDate',
			type: 'date',
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
		},
		{
			label: '是否可信',
			prop: 'isBelievable',
			custome: 'tag',
			dicData: [
				{ label: '否', value: 0,type:'danger' },
				{ label: '是', value: 1,type:'success' },
			],
		},
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}
const importConfig = {
	tabSteps: [
		{
			label: '下载模板',
			download: '下载模板',
			active: 1,
			rules: [
				{
					label: '下载最新导入模板。共1个：',
					children: [
						{
							label: '《医疗机构补贴信息表》',
							link: true,
							url: 'dpMedicalOrganizationSubsidy_downloadTemplate',
						},
					],
				},
			],
		},
		{
			label: '导入《医疗机构补贴信息表》',
			description: '',
			uploadTip: '医疗机构补贴信息表',
			active: 2,
			url: 'dpMedicalOrganizationSubsidy_import',
			code: 3004,
			rules: [
				{
					label: '导入规则说明:',
					children: [
						{
							label: '(1)导入模式为“覆盖导入”，待导入的医疗机构补贴信息会覆盖平台已存在的',
						},
					],
				},
			],
		},
	],
	dataType: 99,
}
const detailConfig:any = {
	label: '医疗机构补贴详情',
	prop: 'base1',
	inline: false,
	showBtn: false,
	labelPosition: 'left',
	column: [
		// 基础信息
		{
			type: 'DividerHtml',
			modelValue: '基础信息',
			span: 24,
		},
		{
			label: '机构名称',
			prop: 'organizationName',
			type: 'text',
			maxlength: '50',
			showWordLimit: true,
			span: 8,
		},
		{
			label: '统一社会信用代码',
			prop: 'creditCode',
			type: 'text',
			maxlength: '18',
			showWordLimit: true,
			span: 8,
		},
		{
			label: '法定代表人',
			prop: 'deputyUserName',
			type: 'text',
			maxlength: '20',
			showWordLimit: true,
			span: 8,
		},
		{
			label: '所属区划',
			prop: 'areas_name',
			type: 'AplidAreaSelect',
			span: 8,
		},
		{
			label: '机构地址',
			prop: 'organizationAddress',
			type: 'text',
			maxlength: '50',
			showWordLimit: true,
			span: 8,
		},
		{
			label: '联系方式',
			prop: 'contactPhone',
			type: 'text',
			maxlength: '11',
			showWordLimit: true,
			span: 8,
		},
		{
			label: '养老机构营业执照（民非）证号',
			prop: 'organizationLicenseCode',
			type: 'text',
			maxlength: '50',
			showWordLimit: true,
		},
		{
			label: '养老机构设置证号（备案）',
			prop: 'organizationFilingCode',
			type: 'text',
			maxlength: '50',
			showWordLimit: true,
			span: 8,
		},
		{
			label: '开户银行',
			prop: 'bankName',
			type: 'text',
			maxlength: '50',
			showWordLimit: true,
			span: 8,
		},
		{
			label: '银行账户',
			prop: 'bankAccount',
			type: 'text',
			maxlength: '50',
			showWordLimit: true,
			span: 8,
		},
		{
			label: '开展养老服务时间',
			prop: 'startServiceDate',
			type: 'date',
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
			span:8,
		},
		{
			label: '开展医疗服务时间',
			prop: 'startMedicalDate',
			type: 'date',
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
			span: 8,
		},
		{
			label: '医疗机构名称',
			prop: 'medicalOrganizationName',
			type: 'text',
			maxlength: '50',
			showWordLimit: true,
			span: 8,
		},
		{
			label: '医疗机构执业许可证号',
			prop: 'medicalPermitCreditCode',
			type: 'text',
			maxlength: '50',
			showWordLimit: true,
			span: 8,
		},
		{
			label: '已领取补贴金额',
			prop: 'receivedFlag',
			type: 'input',
			append:'元',
			span:8,
		},

		// 申请内容
		{
			type: 'DividerHtml',
			modelValue: '申请内容',
			span: 24,
		},
		{
			label: '医疗机构类型',
			prop: 'medicalOrganizationType',
			propName:'medicalOrganizationTypeLabel',
			code:'MEDICAL_INSTITUTE',
			api:'getDictItemList',
			type: 'remoteSelect',
			span: 8,
		},
		{
			label: '补贴金额(小写)',
			prop: 'applyAmount',
			type: 'input',
			append:'元',
			span: 8,
		},
		{
			label: '补贴金额(大写)',
			prop: 'applyAmountText',
			type: 'input',
			span: 8,
		},
		{
			label: '申请日期',
			prop: 'applyDate',
			type: 'date',
			format:'YYYY年MM月DD日',
			valueFormat:'YYYY-MM-DD',
			span: 8,
		},
		//  申请材料
		{
			type: 'DividerHtml',
			modelValue: '申请材料',
			span: 24,
		},
		{
			label: '医疗机构执业许可证明',
			prop: 'applyPermitProveFile',
			type: 'upload',
			fileType: uploadType.fileMetaType,
			listType: 'text',
			showFileList: true,
			limit: 1,
			multiple: true,
			span: 8,
		},
		{
			label: '医疗机构从业人员名单',
			prop: 'applyStaffFile',
			type: 'upload',
			fileType: uploadType.fileMetaType,
			listType: 'text',
			showFileList: true,
			limit: 1,
			multiple: true,
			span: 8,
		},
		{
			label: '养老机构设置相关证件',
			prop: 'applySettingOtherFile',
			type: 'upload',
			fileType: uploadType.fileMetaType,
			listType: 'text',
			showFileList: true,
			limit: 1,
			multiple: true,
			span: 8,
		},
		{
			label: '医疗机构执业许可证或备案',
			prop: 'applyMedicalPermitFile',
			type: 'upload',
			fileType: uploadType.fileMetaType,
			listType: 'text',
			showFileList: true,
			limit: 1,
			multiple: true,
			span: 8,
		},
		// 审核意见
		{
			type: 'DividerHtml',
			modelValue: '审核意见',
			span: 24,
		},
		{
			label: '区民政局审核意见',
			prop: 'civilApprovalNote',
			type: 'text',
			maxlength: '140',
			showWordLimit: true,
			span: 8,
		},
		{
			label: '区民政局审核人',
			prop: 'civilApprovalUserName',
			type: 'text',
			maxlength: '20',
			showWordLimit: true,
			span: 8,
		},
		{
			label: '区民政局审核日期',
			prop: 'civilApprovalDate',
			type: 'date',
			format:'YYYY年MM月DD日',
			valueFormat:'YYYY-MM-DD',
			span: 8,
		},
		{
			label: '区财政局审核意见',
			prop: 'financeApprovalNote',
			type: 'text',
			maxlength: '140',
			showWordLimit: true,
			span: 8,
		},
		{
			label: '区财政局审核人',
			prop: 'financeApprovalUserName',
			type: 'text',
			maxlength: '20',
			showWordLimit: true,
			span: 8,
		},
		// {
		// 	label: '区民政局审核意见',
		// 	prop: 'civilApprovalNote',
		// 	type: 'input',
		// 	span: 8,
		// },
		{
			label: '区财政局审核日期',
			prop: 'financeApprovalDate',
			type: 'date',
			format:'YYYY年MM月DD日',
			valueFormat:'YYYY-MM-DD',
			span: 8,
		},
		// 审批结果
		{
			type: 'DividerHtml',
			modelValue: '审批结果',
			span: 24,
		},
		{
			label: '审批结果',
			prop: 'approvalResult',
			propName:'approvalResultLabel',
			code:"RESULT",
			api:'getDictItemList',
			type: 'remoteSelect',
			span: 8,
		},
		{
			label: '审批人',
			prop: 'approvalUserName',
			type: 'text',
			maxlength: '20',
			showWordLimit: true,
			span: 8,
		},
		{
			label: '审批时间',
			prop: 'approvalDate',
			type: 'date',
			format:'YYYY年MM月DD日',
			valueFormat:'YYYY-MM-DD',
			span: 8,
		},
		{
			label: '补贴发放总金额',
			prop: 'grantAmount',
			type: 'input',
			append:'元',
			span: 8,
		},
		{
			label: '补贴发放时间',
			prop: 'grantDate',
			type: 'date',
			format:'YYYY年MM月DD日',
			valueFormat:'YYYY-MM-DD',
			span: 8,
		},
	],
}
const moreSearchConfig:any = {
	inline: true,
	showBtn: false,
	labelPosition: 'left',
	column:[
		...configToSearch(detailConfig.column)
	]
}
export const baseConfig: any = {
	pageName: '医疗机构补贴',
	dictcodes: ['SUBSIDY_APPLICATION_DISBURSEMENT_TYPE', 'MEDICAL_INSTITUTE','RESULT'],
	rowKey: 'id',
	tipLabel: 'organizationName',
	exportMqTopic: '/ning/export',
	api: {
		moreSearch:'view_dpMedicalOrganizationSubsidy_search',
		index: 'dpMedicalOrganizationSubsidy_page',
		delete: 'dpMedicalOrganizationSubsidy_del',
		export: 'dpMedicalOrganizationSubsidy_export',
		import: 'dpMedicalOrganizationSubsidy_import',
	},
	auth: {
		index: 'view_dpMedicalOrganizationSubsidy_page',
		mulitSet: 'mulitSet',
		delete: 'view_dpMedicalOrganizationSubsidy_del',
		// export: 'view_dpMedicalOrganizationSubsidy_export',
		// import: 'view_dpMedicalOrganizationSubsidy_import',
	},
	menuBtn: [
		{
			icon: 'editor',
			label: '查看详情',
			type: 'primary',
			operate: 'detail',
			auth: '',
			text: true,
			show: true,
		},
	],
	dialogConfig: {
		width: '65%',
	},
	searchConfig: {
		inline: true,
		showBtn: true,
		labelPosition: 'left',
		column: [
			{
				label: '信用代码',
				prop: 'creditCode',
				type: 'input',
				span: 6,
			},
			{
				label: '机构名称',
				prop: 'organizationName',
				type: 'input',
				span: 6,
			},
			{
				label: '联系方式',
				prop: 'contactPhone',
				type: 'input',
				span: 6,
			},
			{
				label: '所属地区',
				propName: 'areas_name',
				type: 'AplidAreaSelect',
				span: 6,
			},
			{
				label: '医疗机构',
				prop: 'medicalOrganizationName',
				type: 'input',
				span: 6,
			},
			{
				label: '申请时间',
				prop: 'applyDateBetween',
				type: 'daterange',
				format: 'YYYY年MM月DD日',
				valueFormat: 'YYYY-MM-DD',
				span: 12,
			},
		],
	},
	moreSearchConfig,
	detailConfig,
	tableConfig,
	importConfig,
	beforeOnLoadFormate: async (params) => {
		params = toSearchHandle(moreSearchConfig,{},params)

		// let applyDateBetween = undefined
		// if (params.timeRangeData) {
		// 	applyDateBetween = params.timeRangeData.join(',')
		// }
		let areasObj = getAreaObj(params.areas_name, 'belong')
		return Promise.resolve({
			...params,
			...areasObj,
			areas_name:undefined
		})
	},
	onLoadFormate: async (arr) => {
		const tableData = arr.map((item) => {
			const areas_name = getAreaObj(item, 'belong')
			return {
				...item,
				areas_name,
			}
		})
		return Promise.resolve(Object.freeze(tableData))
	},
}
